﻿package com.saint.utils
{
	import com.saint.utils.events.ScreenFadeEvent;
	import com.saint.utils.Logger;
	import flash.display.Sprite;
	import caurina.transitions.Tweener;
	
	/**
	 * BLACK SCREEN FADE DISPATCHING EVENTS WHEN TWEENS IN /OUT ARE COMPLETE
	 *
	 *
	 * @author ...
	 */
	public class ScreenFade extends Sprite
	{
		private var _maxAlpha:Number;

		
		public function ScreenFade(width:Number= 150, height:Number = 150, maxAlpha:Number = 0.5)
		{
			Logger.info("ScreenFade.Screenfade: " + width)
			graphics.beginFill(0x000000, 1);
			graphics.drawRect(0, 0, width, height);
			_maxAlpha = maxAlpha;
			this.alpha  =_maxAlpha;
		}
		
		public function fadeIn(time:Number = 1):void
		{
			Tweener.addTween(this, { alpha:maxAlpha , time:time, onComplete:onFadeInComplete} );
		}
		
		public function fadeOut(time:Number = 1):void
		{
			Tweener.addTween(this, { alpha:0 ,time:time,  onComplete:onFadeOutComplete} );
		}
				
		private function onFadeInComplete():void
		{
			dispatchEvent(new ScreenFadeEvent(ScreenFadeEvent.FADE_IN_COMPLETE));
		}
		
		private function onFadeOutComplete():void
		{
			dispatchEvent(new ScreenFadeEvent(ScreenFadeEvent.FADE_OUT_COMPLETE));
		}

		
		
		/**
		 * GETTERS / SETTERS
		 */
		public function get maxAlpha():Number { return _maxAlpha; }
		
		
	}
	
}